<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="resources/layui/css/index.css" media="all" />
    <!-- 引入 echarts.js -->
    <script src="https://cdn.staticfile.org/echarts/4.3.0/echarts.min.js"></script>
</head>
<body class="childrenBody">
<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
<div id="main" style="width: 100%;height:480px;"></div>

<script type="text/javascript" src="resources/layui/layui/layui.js"></script>
<script th:inline="none">

    layui.use(['form','layer','laydate','table','laytpl','jquery'],function() {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var labelRight = {
            normal: {
                position: 'right'
            }
        };
        $(function () {
            getData();
        });
        function  getData() {
            $.ajax({
                type: "GET",
                dataType: 'text',
                url: "/cars/showAll.do",
                data: {},
                cache: false,
                async: true,
                success: function (data) {
                    var data = eval('(' + data + ')');
                    console.log("*****"+data);
                    var data1 = new Array();
                    var data2 = new Array();
                    for(var i=0; i < data.length; i++){
                        data1[i]=data[i].carNo;
                        data2[i]=data[i].totalAmount;
                    }
                    // console.log("*****"+data1);
                    // console.log("*****"+data2);
                    var myChart = echarts.init(document.getElementById('main'));
                    // 指定图表的配置项和数据
                    option = {
                        title: {
                            text: '车辆总费用',
                            subtext: '所有车辆',
                            padding: 5, // 标题内边距，单位px，默认各方向内边距为5
                            itemGap: 10, // 主副标题纵向间隔，单位px，默认为10
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'axis',
                            formatter: "车牌号 : {b} <br/>总费用: {c} "
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'category',
                            data: data1
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            name: '车辆总费用',
                            type: 'bar',
                            barMaxWidth: '100',
                            smooth: true,
                            barCategoryGap: 25,
                            lineStyle: {
                                normal: {
                                    width: 3,
                                    shadowColor: 'rgba(0,0,0,0.4)',
                                    shadowBlur: 10,
                                    shadowOffsetY: 10
                                }
                            },
                            data: data2,
                        }]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                }
            });
        }
    })
</script>
</body>
</html>